package com.hmy.pig.controller;

import com.hmy.pig.domain.HmyPig;
import com.hmy.pig.service.PigService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 猪只信息
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/pig")
public class PigController extends BaseController {


    @Autowired
    private PigService pigService;


    /**
     * 获取猪只列表
     */
    @RequiresPermissions("hmy:pig:list")
    @Log(title = "猪只查询", businessType = BusinessType.OTHER)
    @GetMapping("/list")
    public TableDataInfo list(String pigCode,
                              String phouseType,
                              String pigBirthdayStart,
                              String pigBirthdayEnd)
    {
        startPage();
        List<HmyPig> list = pigService.selectPigList(pigCode,phouseType,pigBirthdayStart,pigBirthdayEnd);
        return getDataTable(list);
    }


    /**
     * @param hmyPig
     * @return com.ruoyi.common.core.web.domain.AjaxResult
     * @author ZHL
     * @date 2024/1/29 15:22
     * @description
     */
    @RequiresPermissions("hmy:pig:add")
    @Log(title = "猪只档案管理", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@Validated @RequestBody HmyPig hmyPig)
    {
        return AjaxResult.success(pigService.insertPig(hmyPig));
    }
    /**
     * @param pigId
     * @return com.ruoyi.common.core.web.domain.AjaxResult
     * @author ZHL
     * @date 2024/1/30 10:05
     * @description  通过猪只耳号 查询猪只档案信息
     */
    @RequiresPermissions("hmy:pig:query")
    @GetMapping("getInfo/{pigId}")
    public AjaxResult selectByPigId(@PathVariable Long pigId){
        return  AjaxResult.success(pigService.selectPigByPigId(pigId));
    }
    /**
     * @param pigCode
     * @return com.ruoyi.common.core.web.domain.AjaxResult
     * @author ZHL
     * @date 2024/1/30 10:05
     * @description  通过猪只耳号 查询猪只档案信息
     */
    @RequiresPermissions("hmy:pig:query")
    @GetMapping("getPigByPigCode/{pigCode}")
    public AjaxResult selectByPigCode(@PathVariable String pigCode){
        return  AjaxResult.success(pigService.selectPigByPigCode(pigCode));
    }


    /**
     * @param hmyPig
     * @return com.ruoyi.common.core.web.domain.AjaxResult
     * @author ZHL
     * @date 2024/1/30 10:24
     * @description  更新猪只档案信息
     */
    @PostMapping("update")
    @RequiresPermissions("hmy:pig:update")
    @Log(title = "猪只档案管理", businessType = BusinessType.UPDATE)
    public AjaxResult updatePig(@RequestBody HmyPig hmyPig){
        return AjaxResult.success(pigService.updatePig(hmyPig));
    }

    /**
     * @param pigIds
     * @return com.ruoyi.common.core.web.domain.AjaxResult
     * @author ZHL
     * @date 2024/1/30 14:45
     * @description   根据id删除 批量 猪只档案信息
     */
    @DeleteMapping("del/{pigIds}")
    @RequiresPermissions("hmy:pig:del")

    public AjaxResult deleteByPigIds(@PathVariable("pigIds") Long[] pigIds){
        return  AjaxResult.success(pigService.deletePigByPigIds(pigIds));
    }
    /**
     * @param pigType
     * @return com.ruoyi.common.core.web.domain.AjaxResult
     * @author ZHL
     * @date 2024/3/1 13:48
     * @description  根据传入的pigType 查询猪只数量
     */
    @RequiresPermissions("hmy:pig:query")
    @GetMapping("selectPigNum")
    public AjaxResult selectPigNum(String pigType){
        return  AjaxResult.success(pigService.selectPigNum(pigType));
    }

}
